package com.whu.zqm.service;

import com.whu.zqm.dao.SupplierJPARepository;
import com.whu.zqm.entity.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SupplierService {
    @Autowired
    private final SupplierJPARepository supplierRepository;

    public SupplierService(SupplierJPARepository supplierRepository) {
        this.supplierRepository = supplierRepository;
    }
    public List<Supplier> getSuppliers() {
        return supplierRepository.findAll();
    }


    public Supplier addSupplier(Supplier s){
        return supplierRepository.saveAndFlush(s);
    }

    public Supplier getSupplier(long id){
        return supplierRepository.getById(id);
    }

    public void deleteSupplier(long id){
        supplierRepository.deleteById(id);
    }
}
